package com.xiaoming.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 产品线枚举
 *
 * @author xiaoming
 * @Date 2020/5/12
 * @blame java Team
 */
@Getter
@AllArgsConstructor
public enum  ProductLine {

    PRODUCT_ONE("产品线一", 1),
    PRODUCT_TWO("产品线二", 2);

    /**
     * 产品线描述
     */
    private final String description;

    /**
     * 产品线编码
     */
    private final Integer code;

    /**
     * 根据code获取对应枚举
     * @param code
     * @return
     */
    public static ProductLine of(Integer code){
        Objects.requireNonNull(code);

        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + " not exists!"));
    }
}
